package com.bt.controller.admin;
import com.bt.dto.YddLinkDTO;
import com.bt.dto.YddLinkPageQueryDTO;
import com.bt.result.PageResult;
import com.bt.result.Result;
import com.bt.service.YddLinkService;
import com.bt.vo.YddLinkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-05-02 11:34
 */
@RestController
@Slf4j
@Api(tags = "友情链接管理")
/*@RequestMapping("/admin/ydd_link")*/
@RequestMapping("/ydd_link")
public class YddLinkController {
    @Autowired
    private YddLinkService yddLinkService;

    /**
     * 友情链接详情
     *
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("友情链接详情接口")
    public Result rowInfo(Integer id) {
        log.info("友情链接详情{}", id);
        YddLinkVO yddLinkVO = yddLinkService.rowInfo(id);
        return Result.success(yddLinkVO);
    }

    /**
     * 链接修改
     *
     * @param yddLinkDTO
     * @return
     */
    @ApiOperation("链接修改接口")
    @PostMapping("/update")
    public Result update(@RequestBody YddLinkDTO yddLinkDTO) {
        log.info("链接修改{}", yddLinkDTO);
        yddLinkService.update(yddLinkDTO);
        return Result.success();
    }


    /**
     * 链接删除
     *
     * @param id
     * @return
     */
    @ApiOperation("链接删除接口")
    @GetMapping("/del")
    public Result del(Integer id) {
        log.info("链接删除{}", id);
        yddLinkService.del(id);
        return Result.success();
    }

    /**
     * 链接添加
     *
     * @return
     */

    @PostMapping("/add")
    public Result add(@RequestBody YddLinkDTO yddLinkDTO) {
        log.info("链接添加{}", yddLinkDTO);
        yddLinkService.add(yddLinkDTO);
        return Result.success();
    }


    /**
     * 分页链接列表
     *
     * @return
     */
    @ApiOperation("分页链接列表接口")
    @GetMapping("/list")
    public Result list(YddLinkPageQueryDTO yddLinkPageQueryDTO) {
        log.info("分页链接列表{}", yddLinkPageQueryDTO);
        PageResult pageResult = yddLinkService.list(yddLinkPageQueryDTO);
        return Result.success(pageResult);
    }


}
